<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        /* .layout{
            height: 100%; 不行 100%是根据body来定的，而body是由内容撑起来的
            height: 100vh;
        } */
        /* 这样写更优 单屏应用 */
        html,
        body,
        .layout {
            height: 100%;
        }

        .layout {
            color: #fff;
            text-align: center;
            display: flex;
            /*创建BFC*/
            justify-content: space-around;
        }

        .grid {
            /*GFC*/
            display: grid;
            /* 二维的布局 */
            grid-template-rows: 50px 1fr 50px;
            /* 每行占位设置 */
        }

        header,
        footer {
            line-height: 50px;
        }


        main {
            overflow-y: auto;
        }

        section {
            width: 20%;
            margin: 20px 0;
        }

        .h50 {
            height: 50px;
            line-height: 50px;
        }

        .orange {
            background-color: orange;
        }

        .blue {
            background-color: blue;
        }

        .black {
            background-color: black;
        }

        .flex {
            display: flex;
            flex-direction: column;
        }

        .flex main {
            flex: 1;
        }

        .demo2 {
            position: relative;
            /* padding: 50px 0; */
        }

        .demo2 header {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
        }

        .demo2 footer {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
        }

        .demo2 main {
            padding: 50px 0;
            box-sizing: border-box;
            /* 导致盒子模型改变 宽高只是content高度，不包括边框和内外边距 */
            height: 100%;
            /* height: 100%; 父容器除去 padding 的高度 */
        }

        .demo1 main {
            height: calc(100% - 100px);
            /* 计算符号 两边记得空格 */
        }
    </style>
</head>

<body>
    <div class="layout">
        <section class="grid">
            <header class="orange">方法一：grid</header>
            <main class="blue">
                main
            </main>
            <footer class="black">footer</footer>
        </section>
        <section class="flex">
            <header class="orange">方法二：flex</header>
            <main class="blue">
                main
            </main>
            <footer class="black">footer</footer>
        </section>
        <section class="demo2">
            <header class="h50 orange">方法三：absolute</header>
            <main class="blue">
                main
            </main>
            <footer class="h50 black">footer</footer>
        </section>
        <section class="demo1">
            <header class="h50 orange">方法四：calc</header>
            <main class="blue">
                main
            </main>
            <footer class="h50 black">footer</footer>
        </section>
    </div>
</body>

</html>